<!--有选择按钮表格-->
<template>
    <div class='tableEdit' :style="heights">
        <div style='margin-bottom:0px;text-align:left'>
            <el-button type="warning" style='margin-bottom:10px;width:80px' @click="addRow" v-if="isAdd=='Y'">新增行</el-button>
            <input-button-select ref="inputSelectList" @openWin="openWin" :label="item.label"  :id="item.id"  :data="data" :extype="item.extype" :exkey="item.exkey"   v-for="(item,index) in buttons" :key="index" :appid="appid"></input-button-select>
        </div>
        <div v-if="showTabs" style="padding:5px;text-align:left">
             <el-button-group>
                <el-button type="primary" plain class="" @click="changeAll()" :class="{'tabActive':tabName=='全部'}">全部</el-button>
                <el-button type="primary" plain v-for="(item,index) in tabs" :key="index" @click="changeItem(item)" :class="{'tabActive':tabName==item.name}">{{item.name}}</el-button>
                 
             </el-button-group>
        </div>
        <div style='flex:1;overflow:auto'>
            <el-table
                
                :data="data[dataField]"
                class='tablesss'
                height="100%"
                border
                @filter-change="filterChanged"
                v-if="shows&&isNative!='Y'"
               
                style="width: 100%;">
                <el-table-column
                :filters="filters[item.id]"
                :filter-method="filterMethod"
                :column-key="item.id"
                v-for="(item,index) in listNew" :key="index"
                    :label="item.label"
                :width='item.width.replace("width:","")' >
                    <template slot-scope="scope"  >
                        <div @click="cellClick(scope.$index,scope.row,index)" v-if="scope.row['editor']!='Y'&&(item.type=='text'||scope.inputtype=='text')"  :style='{"padding":"5px 15px","width":item.width.replace("width:","").replace("pxpx","px"),"height":"30px"}'> {{scope.row[item.id]}}</div>
                        <div @click="clickEvent(item,scope.$index)"  v-if="scope.row['editor']=='Y'&&item.isReadOnly=='Y'&&(item.type=='text'||scope.inputtype=='text')"  :style='{"padding":"5px 15px","width":item.width.replace("width:","").replace("pxpx","px"),"height":"30px"}'> {{scope.row[item.id]}}</div>
                        
                        <input-card-button :id="item.id" :isreadonly="item.isReadOnly" :extype="item.extype" :exkey="item.exkey"  :data="data"  @input="tableChangeData" :expost="item.expost"   :index="scope.$index"  v-if="item.type=='inputCardButton'"></input-card-button>
                    
                        <input-button-select @openWin="openWin" ref="inputSelectList" :label="item.label"  :id="item.id"  :data="data" :extype="item.extype" :exkey="item.exkey"  :index="scope.$index"  :appid="appid" v-if="item.type=='inputButtonSelect2'"></input-button-select>
                        <el-button type="primary" @click.native="print(item,scope.$index)" v-if="item.type=='inputLinePrintButton'">打印</el-button>
                        <input-noborder @blur="cellBlur(scope.row)" @click.native="clickEvent(item,scope.$index)"  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :exdata="scope.$index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData" :autofocus="cellIndex==index"  :isreadonly="item.isReadOnly"  v-if="(item.type=='text'||scope.inputtype=='text')&&scope.row['editor']=='Y'&&item.isReadOnly!='Y'"></input-noborder>
                        <component :is="item.type" @click.native="clickEvent(item,scope.$index)"  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :exdata="scope.$index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData"  :isreadonly="item.isReadOnly"  v-if="item.type=='glfBatch'"></component>
                        <input-select ref="inputSelect" :selectData="selectData"  :attribute="item" :id="item.id" :valsql="item.valsql" :sign="item.sign" :time="item.time" isBorder="N" :dataField="dataField" styles="width:100%" :options="item.dataSource" :index="scope.$index" :exkey="item.exkey"  :data="data"  @input="tableChangeData" :isreadonly="item.isReadOnly" v-if="item.type=='select'&&scope.inputtype!='text'" ></input-select>
                        <input-number @click.native="clickEvent(item,scope.$index)"  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :exdata="scope.$index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData"  :isreadonly="item.isReadOnly"  v-if="(item.type=='number'||scope.inputtype=='number')"></input-number>
                    
                        <input-select ref="inputSelect" isEdit="Y"  :selectData="selectData"   :attribute="item" :id="item.id" :valsql="item.valsql" :sign="item.sign" :time="item.time" isBorder="N" :dataField="dataField" styles="width:100%" :options="item.dataSource" :index="scope.$index" :exkey="item.exkey"  :data="data"  @input="tableChangeData" :isreadonly="item.isReadOnly" v-if="item.type=='select'&&scope.inputtype=='text'" ></input-select>
                        <input-select-multiple ref="inputSelect" :attribute="item" :id="item.id" :valsql="item.valsql" :sign="item.sign" :time="item.time" isBorder="N" :dataField="dataField" styles="width:100%" :options="item.dataSource" :index="scope.$index" :exkey="item.exkey"  :data="data"  @input="tableChangeData" :isreadonly="item.isReadOnly" v-if="item.type=='selectmultiple'" ></input-select-multiple>
                        <input-card @click.native="clickEvent(item,scope.$index)"  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :index="scope.$index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData"  :isreadonly="item.isReadOnly"  v-if="item.type=='idcard'"></input-card>
                        
                        
                        <!--input-select :attribute="item"   isBorder="N" :dataField="dataField"  :index="scope.$index"  :data="data"  @input="tableChangeData" v-if="item.type=='select'" ></input-select-->
                        <input-date :id="item.id"   isBorder="N" :dataField="dataField"  styles="width:100%"  :index="scope.$index"  :data="data"  @input="tableChangeData" v-if="item.type=='date'"></input-date>
                        <input-datetime :id="item.id"   isBorder="N" :dataField="dataField"  styles="width:100%"  :index="scope.$index"  :data="data"  @input="tableChangeData" v-if="item.type=='datetime'"></input-datetime>
                        <city-select @click.native="clickEvent(item,scope.$index)"  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :exdata="scope.$index"  :index="scope.$index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData"  :isreadonly="item.isReadOnly"  v-if="item.type=='cityselect'"></city-select>
                        <sign-view ref="signView"  :attribute="item" :id="item.id" :valsql="item.valsql" :sign="item.sign" :time="item.time" isBorder="N" :dataField="dataField" styles="width:100%" :options="item.dataSource" :index="scope.$index" :exkey="item.exkey"  :data="data"  @input="tableChangeData" :isreadonly="item.isReadOnly" v-if="item.type=='signView'" ></sign-view>
                    
                    </template>
                    
                </el-table-column>
                <el-table-column
                label="操作"
                v-if="lineButtons.length>0"
                :width='lineButtons[0].width.replace("width:","")'
            >
                <template slot-scope="scope">
                    <template v-for="(item,index) in lineButtons">
                        <el-button type="primary" size="small"   @click="openWinEdit(item,scope.$index)" v-if="scope.row[item.id]!='N'&&scope.row[item.id]!='A'">{{item.label}}</el-button>
                        <el-button type="info" size="small"   v-else-if="scope.row[item.id]=='N'">{{item.label}}</el-button>
                    </template>
                </template>
                </el-table-column>
            <el-table-column
                label="删除"
                width="60"
                v-if="isDel!='N'"
            >
                <template slot-scope="scope">
                    <el-tooltip content="点击删除该信息" placement="top" v-if="scope.isNotDel!='Y'">
                            <i class='el-icon-delete' style='cursor:pointer;font-size:28px' @click="removeItem(scope.$index)" ></i>
                        </el-tooltip>
                    
                </template>
                </el-table-column>
            </el-table>
            <table cellspacing=0 cellpadding=0 v-if="shows&&isNative=='Y'" style='table-layout:fixed'>
                <colgroup>
                    <col style="width:40px"/>
                    <col v-for="(item,index) in listNew" :key="index" :style='item.width'/>
                    <col style='width:48px'/>
                    <col/>
                </colgroup>
                <tr>
                    <th>NO.</th>
                    <th v-for="(item,index) in listNew" :key="index">
                        {{item.label}}
                    </th>
                    <th>&nbsp;</th>
                </tr>
                <template  v-for="(item2,index) in data[dataField]">

                    <tr :key="index" v-if="item2.isShow!='N'&&item2.isshow!='N'" :class="{'activeRow':activeIndex==index}" @click="activeIndex=index">
                        <td style="text-align:center">{{item2.No}}</td>
                        <td v-for="(item,index2) in listNew" :key="index2">
                          
                            <input-button-select @openWin="openWin" ref="inputSelectList" :label="item.label"  :id="item.id" :blurChange="blurChange"  :data="data" :extype="item.extype" :exkey="item.exkey"  :index="index"  :appid="appid" v-if="item.type=='inputButtonSelect2'"></input-button-select>
                            <el-button type="primary" @click.native="print(item,index)" v-if="item.type=='inputLinePrintButton'">打印</el-button>
                            <input-noborder  :blurChange="blurChange"  @click.native="clickEvent(item,index)"  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :exdata="index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData"  :isreadonly="(item2.szi_ex33s||item2.szi_ex33||item.isReadOnly||item2.isReadOnly||item2.isreadonly)"  v-if="item.type=='text'&&item.id=='szi_ex2'&&item2.isReadOnly!='Y'"></input-noborder>
                            <input-xm :item="item" @click.native="clickEvent(item,index)"   :dataField="dataField"  :data="data" :index="index" @input="tableChangeData" :readonly="item2.szi_ex33" :appid="appid"  v-if="item.type=='selectxm'"></input-xm>
 
                            <input-noborder  :blurChange="blurChange"  @click.native="clickEvent(item,index)"  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :exdata="index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData"  :isreadonly="(item.isReadOnly||item2.isReadOnly||item2.isreadonly)"   v-if="item.type=='text'&&item.id!='szi_ex2'&&item2.isReadOnly!='Y'"></input-noborder>
                            
                            <input-noborder  :blurChange="blurChange"  @click.native="clickEvent(item,index)"  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :exdata="index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData"  isreadonly="Y"   v-if="item2.isReadOnly=='Y'"></input-noborder>
                              
                            <component  :blurChange="blurChange"  :is="item.type" @click.native="clickEvent(item,index)"  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :exdata="index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData"  :isreadonly="(item.isReadOnly||item2.isReadOnly||item2.isreadonly)"  v-if="item.type=='glfBatch'"></component>
                            <input-select   ref="inputSelect" :attribute="item" :id="item.id" :valsql="item.valsql" :sign="item.sign" :time="item.time" isBorder="N" :dataField="dataField" styles="width:100%" :options="item.dataSource" :index="index" :exkey="item.exkey"  :data="data"  @input="tableChangeData" :isreadonly="item.isReadOnly" v-if="item.type=='select'" ></input-select>
                        
                            <!--input-select :attribute="item"   isBorder="N" :dataField="dataField"  :index="scope.$index"  :data="data"  @input="tableChangeData" v-if="item.type=='select'" ></input-select-->
                            <input-date :id="item.id"   isBorder="N" :dataField="dataField"  styles="width:100%"  :index="index"  :data="data"  @input="tableChangeData" v-if="item.type=='date'"></input-date>
                            <input-datetime :id="item.id"   isBorder="N" :dataField="dataField"  styles="width:100%"  :index="index"  :data="data"  @input="tableChangeData" v-if="item.type=='datetime'"></input-datetime>
                            <city-select @click.native="clickEvent(item,index)"  :id="item.id" :dataField="dataField" ref="inputs" :data="data" :exdata="index" :index="index" :extype="item.extype" :exkey="item.exkey" @input="tableChangeData"  :isreadonly="item.isReadOnly||item2.szi_ex33"  v-if="item.type=='cityselect'"></city-select>
                            
                        
                        </td>
                        <td style='text-align:center;padding:5px'>
                            <el-tooltip content="点击删除该信息" placement="top" v-if="item2.isNotDel!='Y'&&item2.isnotdel!='Y'&&isDel!='N'&&item2.isReadOnly!='Y'">
                                <i class='el-icon-delete' style='cursor:pointer;font-size:28px' @click="removeItem(index)" ></i>
                            </el-tooltip>
                        </td>
                    </tr>
                </template>
            </table>
        </div>
        <!--table cellspacing=0 cellpadding=0>
            <colgroup>
                <col v-for="(item,index) in listNew" :key="index" :style='item.width'/>
                <col style='width:18px'/>
            </colgroup>
            <tr>
                <th v-for="(item,index) in listNew" :key="index">
                    {{item.label}}
                </th>
                <th>&nbsp;</th>
            </tr>
            <tr v-for="(item,index) in data[dataField]" :key="index">
                <td v-for="(field,index2) in listNew" :key="index2">
                    <input-noborder :id="field.id" :dataField="dataField" ref="inputs" :data="data" :exdata="index" :extype="field.extype" :exkey="field.exkey" @input="tableChangeData"  :isreadonly="field.isReadOnly"  v-if="field.type=='text'"></input-noborder>
                    <input-select :id="field.id"  :dataField="dataField" styles="width:100%" :options="field.dataSource" :index="index"   :data="data"  @input="tableChangeData" :isreadonly="field.isReadOnly" v-if="field.type=='select'" ></input-select>
                    <input-date :id="field.id"   :dataField="dataField"  styles="width:100%"  :index="index"  :data="data"  @input="tableChangeData" v-if="field.type=='date'"></input-date>

                </td>
                <td style='text-align:center;color:red'><i class='fa fa-times' style='cursor:pointer' @click="removeItem(index)"></i></td>
            </tr>
            
        </table-->
        

    </div>
    
</template>
<script>

//import inputNoborder  from '../input/input-noborder'
//import inputSelect from '../input/input-select'
//import inputDate from '../input/input-date'
//import inputButtonSelect from '../input/input-button-select'
export default {
    props:['dataField','listField','data','heights','isreadonly','appid','isDel','isNative','exkey','selectData','tabs','delset','blurChange'],
    name: "table-edit",
    components: {
        InputCard: resolve => {require(['../input/input-card'], resolve)},
       inputNoborder: function (resolve) {
            //异步组件写法
            require(['../input/input-noborder'], resolve)
        },
       inputSelect: function (resolve) {
            //异步组件写法
            require(['../input/input-select'], resolve)
        },
        inputXm: function (resolve) {
            //异步组件写法
            require(['../input/input-xm'], resolve)
        },
       inputDate: function (resolve) {
            //异步组件写法
            require(['../input/input-date'], resolve)
        },
        inputNumber: function (resolve) {
            //异步组件写法
            require(['../input/input-number'], resolve)
        },
         inputDatetime: function (resolve) {
            //异步组件写法
            require(['../input/input-datetime'], resolve)
        },
       inputButtonSelect: function (resolve) {
            //异步组件写法
            require(['../input/input-button-select'], resolve)
        },
       glfBatch: function (resolve) {
            //异步组件写法
            require(['../gm/glfBatch.vue'], resolve)
        },
        citySelect: function (resolve) {
            //异步组件写法
            require(['../input/city-select.vue'], resolve)
        },
        InputCardButton: function (resolve) {
            //异步组件写法
            require(['../input/input-card-button'], resolve)
        },
        InputSelectMultiple: resolve => {require(['../input/input-select-multiple'], resolve)},
        signView: resolve => {require(['../byg/signView'], resolve)},
    },
    inject: ['prints','saves'],
    data(){
        return{
            cellIndex:-1,
            showTabs:false,
            shows:false,
            isAdd:"N",
            buttons:[],
            listNew:[],
            lineButtons:[],
            dataIndex:-1,
            dataType:"",//pre
            dataTemp:{},
            data_exkey:{},
            totalField:"",
            totalFieldTitle:"",
            tabName:"全部",
            activeIndex:-1,
            colors:{},
            empty:{},
            isWatch:true,
            filters:{},
            changeKey:true
        }
    },
    created(){
       
        try{
            if(this.exkey&&this.exkey.totalField){
                this.totalField=this.exkey.totalField;
            }
            if(this.exkey&&this.exkey.totalFieldTitle){
                this.totalFieldTitle=this.exkey.totalFieldTitle;
            }
        }catch(e){}
       
        try{
            if(this.tabs&&this.tabs.length>0){
                this.showTabs=true;
            }
        }catch(e){}
        if(sessionStorage.getItem("commonEdit")){
            this.$set(this.data,this.dataField,JSON.parse(sessionStorage.getItem("commonEdit")));
            sessionStorage.setItem("commonEdit","")
        }
        this.buttons=[];
        this.listNew=[];
        this.lineButtons=[];
        console.log(this.listField,"this.listField===================================");
        for(let i=0;i<this.listField.length;i++){
            this.listField[i].width=this.listField[i].width+"px"
            if(this.listField[i].type=="inputButtonAdd"){
               this.isAdd='Y'
            }else  if(this.listField[i].type=="inputButtonSelect"){
                this.buttons.push(this.listField[i])
            }else if(this.listField[i].type=="inputLineButton"||this.listField[i].type=="inputLineButtonBeforeSave"){
                this.lineButtons.push(this.listField[i]);
            }else{
                this.listNew.push(this.listField[i])
            }
        }
        console.log(this.lineButtons,"lineButtons-------------")
        try{
            if(this.lineButtons&&this.lineButtons.length>0){
               // console.log("this.lineButtons=======")
                this.data[this.dataField].forEach((item,index)=>{
                    this.lineButtons.forEach(button=>{
                       // console.log(button.condition,"condition===")
                        let isOk=true;
                        if(button.exkey&&button.exkey.condition){
                            let conditions=button.exkey.condition;
                           
                            conditions.forEach(condition=>{
                                let field=condition.field;
                                let opr=condition.opr;
                                let val=condition.val;
                                let val_=item[field];

                               // console.log("field================"+field+"="+opr+"="+val+"+"+val_)
                                if(opr=="等于"&&val!=val_){
                                    isOk=false;
                                }
                                if(opr=="不等于"&&val==val_){
                                    isOk=false;
                                }
                            })
                            
                        }
                        if(!isOk){
                            if(button.exkey&&button.exkey.isShow&&button.exkey.isShow=='N')
                                this.data[this.dataField][index][button.id]="A"
                            else
                                this.data[this.dataField][index][button.id]="N"
                        }
                    })
                })
            }
        }catch(e){}
        console.log(this.data[this.dataField])
        try{
            if(this.exkey&&this.exkey.empty){
                this.empty=this.exkey.empty;
            }
        }catch(e){}
      /*  try{
            
            this.$parent.$el.parentNode.parentNode.style.overflow="hidden";
            this.$parent.$el.parentNode.parentNode.style.flexDirection="column";
            this.$parent.$el.parentNode.parentNode.style.flexWrap="nowrap";
            this.$parent.$el.parentNode.style.flexDirection="column";
            this.$parent.$el.parentNode.style.flex="1";
            this.$parent.$el.parentNode.style.display="flex";
            this.$parent.$el.parentNode.style.overflow="hidden";
            
            this.$parent.$el.style.flex="1";

            let height=this.$parent.$parent.$el.clientHeight;
        }catch(e){}*/
        //初始化列表里的编辑数据
        try{    
           
            for(let i=0;i<this.listNew.length;i++){
                
                try{
                    if(this.listNew[i].clickKey){
                        let exkey=this.listNew[i].clickKey;
                        let sId=exkey.sId;
                        let key_field=exkey.key_field;
                        let extype=exkey.extype;
                        let datas=this.data[extype]
                        console.log("this.extype================"+extype);
                        console.log(datas);
                        if(datas){
                            for(let j=0;j<this.data[this.dataField].length;j++){
                        
                                let id__=this.data[this.dataField][j][sId];
                                let items=[];
                                for(let h=0;h<datas.length;h++){
                                    let id___=datas[h][key_field];
                                    if(id__==id___){
                                        items.push(datas[h]);
                                    }
                                }
                                if(items.length>0){
                                    if(!this.dataTemp[extype])
                                        this.dataTemp[extype]={};
                                    this.dataTemp[extype]["a"+j]=items;
                                }
                            

                            }
                        }
                        

                        
                    }
                }catch(e){}

                try{
                    if(this.exkey&&this.exkey.filter){
                       if((","+this.exkey.filter+",").indexOf(","+this.listNew[i].id+",")!=-1){
                         let datas=[];
                         let str="";
                         this.data[this.dataField].forEach(item=>{
                            if((","+str+",").indexOf(item[this.listNew[i].id])==-1){
                                let d={
                                    text:item[this.listNew[i].id],
                                    value:item[this.listNew[i].id]
                                }
                                str=str=="" ? item[this.listNew[i].id]:str+","+item[this.listNew[i].id];
                                datas.push(d)
                            }
                            
                         })
                         this.filters[this.listNew[i].id]=datas;
                         this.changeKey=!this.changeKey
                       }

                    }
                }catch(e){}
                
            }

            console.log(this.dataTemp,"this.dataTEmp=================")
        }catch(e){}

        console.log(this.data[this.dataField],"dataFields===s=s======")
        //alert(this.empty);
       // try{
            if(this.empty){
                
                let rows=Number(this.empty.rows);
                for(let i=0;i<rows;i++){
                    let cols={};
                    for(let key in this.listNew){
                        cols[key]="";
                    }
                    this.isWatch=false;
                    //this.$set(this.data[this.dataField],this.data[this.dataField].length,cols)
                    this.data[this.dataField].push(cols)
                }
                console.log(this.data[this.dataField],"emptys=======")
            }
        //}catch(e){}
    }, 
    computed:{
        dataFields:function(){
           
            let datas=this.data[this.dataField];
            datas.forEach((item,index)=>{
                if(item.no!=index){
                    item.no=index;
                }
            })
            console.log("dataFields=====================================")
            if(this.totalField){
                let totalFields=this.totalField.split(",");
                let totalMap={};
                for(let i=0;i<datas.length;i++){
                    for(let j=0;j<totalFields.length;j++){
                        let key=totalFields[j];
                        let num=Number(datas[i][key]);
                        let total=0;
                        if(totalMap[key]){
                            total=totalMap[key];
                        }
                        total=total+num;
                        totalMap[key]=total;
                    }
                }
                totalMap[this.totalFieldTitle]="合计";
                datas.push(totalMap);
            }
            this.shows=true;
           
           return datas;
        }
    },
    watch:{
         dataFields:{
                handler: function (newVal) {
                   
                   if(this.isWatch){
                        this.shows=false;
                        console.log(this.delset,"this.delset22===============")
                        for(let i=0;i<this.data[this.dataField].length;i++){
                            this.changeAmt(i);
                            try{
                                if(this.delset&&this.delset.length>0){
                                    for(let j=0;j<this.delset.length;j++){
                                        let field=this.delset[j].field;
                                        let opr=this.delset[j].opr;
                                        let val=this.delset[j].val;
                                        let val_=this.data[this.dataField][i][field];
                                        if(val=="sesUserid"){
                                            val=localStorage.getItem("userId")
                                        }
                                        if(opr=="等于"&&val!=val_){
                                            this.data[this.dataField][i].isReadOnly="Y"
                                            break;
                                        }
                                        if(opr=="不等于"&&val==val_){
                                            this.data[this.dataField][i].isReadOnly="Y"
                                            break;
                                        }
                                        //this.data[this.dataField][i].isReadOnly="Y"
                                    }
                                }
                            }catch(e){}
                        }
                        this.shows=true;
                        console.log(this.data[this.dataField],"tableEdit===========ss====")
                        try{
                            if(this.empty){
                                let empty_field=this.empty.field;
                                let empty_row=0;
                                for(let i=0;i<this.data[this.dataField].length;i++){
                                    let field_val=this.data[this.dataField][i][empty_field];
                                    if(!field_val){
                                        empty_row++;
                                    }
                                }
                                let rows=Number(this.empty.rows);
                                for(let i=0;i<rows-empty_row;i++){
                                    let cols={};
                                    for(let key in this.listNew){
                                        cols[key]="";
                                    }
                                    this.isWatch=false;
                                    this.data[this.dataField].push(cols)
                                }
                            }
                        }catch(e){}
                   }else{
                     this.isWatch=true;
                   }
                   
                  
                },      
                deep: true    //深度监听
            }
        
    },
    beforeDestroy(){
        this.$set(this.data,this.dataField,{})
    },
    methods:{
        filterMethod(value, row,column) {
           
            let label=column.label;
            let id="";
            this.listNew.forEach(item=>{
                if(item.label==label){
                    id=item.id;
                }
            })
           
           
            return row[id] === value
        },
        filterChanged(value){
           // console.log(value,"value========")
            
            try{
                if(this.exkey&&this.exkey.filterRel){
                    this.exkey.filterRel.forEach(item=>{
                        let srcKey=item.srcKey;
                        let dstKey=item.dstKey;
                       // console.log("scrKey=="+srcKey+"=="+dstKey)
                        for(let keys in value){
                            console.log("keys=="+keys)
                            let values=value[keys];
                            let val=values.join(",")
                           // console.log("val=="+val+"=="+srcKey)
                            if(srcKey==keys){
                                let datas=[];
                                this.data[this.dataField].forEach(item2=>{
                                    let data={};
                                    if((","+val+",").indexOf(","+item2[keys]+",")!=-1){
                                        data={
                                            text:item2[dstKey],
                                            value:item2[dstKey]
                                        }
                                        datas.push(data)
                                    }
                                })
                                let filters=JSON.parse(JSON.stringify(this.filters))
                                this.filters={}
                                for(let key in filters){
                                    if(key!=dstKey){
                                        this.filters[key]=filters[key]
                                    }
                                }
                                //this.$set(this.filters,dstKey,datas)
                                this.filters[dstKey]=datas;
                                console.log(this.filters[dstKey])
                            }
                        }
                    })
                }
                
            }catch(e){}
        },
        cellClick(index,row,cellIndex){
           
            this.cellIndex=cellIndex;
            if(row.no||row.no=="0"||row.no==0){
                index=row.no;
            }
            this.$set(this.data[this.dataField][index],"editor","Y")
        },
        cellBlur(row){
            this.$set(this.data[this.dataField][row.no],"editor","N")
        },
        changeAll(){
            this.tabName="全部"
            for(let i=0;i<this.data[this.dataField].length;i++){
                
                this.$set(this.data[this.dataField][i],"isShow","Y")
               // this.data[this.dataField][i]["isShow"]=!shows ? "N":"Y"
            }
            this.$emit("changeAmt","")
        },
        changeItem(item){
            console.log(item,"items====")
            this.tabName=item.name;
            let field=item.field;
            let val=item.val;
            let opr=item.opr;
            let vals=item.val.split("#")
            let datas=this.data[this.dataField]
            for(let i=0;i<this.data[this.dataField].length;i++){
                let shows=false;
                let val_=this.data[this.dataField][i][field];
                if(val==val_){
                    shows=true;
                }else{
                    for(let h=0;h<vals.length;h++){
                        console.log("val_========"+val_+"=="+vals[h]+"=="+(val_.indexOf(vals[h])))
                        if(opr=="="){
                            if(val_==vals[h]){
                                shows=true;
                            }
                        }else{
                            if(val_.indexOf(vals[h])!=-1){
                                shows=true;
                            }
                        }
                        
                    }
                }
                //this.$set(this.data[this.dataField][i],"isShow",!shows ? "N":"Y")
                datas[i]["isShow"]=!shows ? "N":"Y"
            }
            this.$set(this.data,this.dataField,datas)
            console.log(this.data[this.dataField],"data------------------")
            this.$emit("changeAmt","")
        },
        validate(){
            console.log("validate=======================")
           console.log(this.listNew);
           console.log(this.data[this.dataField])
           let rules={};
           let resultMsg="";
           for(let i=0;i<this.listNew.length;i++){
               let required=this.listNew[i].required;
               let msg=this.listNew[i].msg;
               let label=this.listNew[i].label;
               let id=this.listNew[i].id;

               
               if(required=="true"){
                   msg=msg=="" ? label+"不能为空":msg;
                   rules[id]=msg;
               }
           }

           for(let i=0;i<this.data[this.dataField].length;i++){
               let item=this.data[this.dataField][i];
               for(let key in rules){
                   let val=item[key];
                   if(!val){
                       resultMsg="第"+(i+1)+"行"+rules[key];
                       break;
                   }
               }
           }
           return resultMsg;
        },
        setDataSource(index,item){
            console.log(this.$refs.inputSelect[index])
            this.$refs.inputSelect[index].setSource(item)
           // this.$set(this.listNew[index],"dataSource",item);
            //console.log(this.listNew)
        },
        print(item,index){
            let exkey=item.exkey;
            let name=exkey.name;
            let id=exkey.id;
           
            let val=this.data[this.dataField][index][id];
            new Promise((resolve, reject) => {
                this.saves({url:"api/view/saveCommonEdit",isAlert:"N"},resolve);
            }).then(data=>{
                this.prints(name,val,exkey.isPrint);

            });
            
        },
        clickEvent(item,index){
            let clickKey=item.clickKey;
          
            if(item.clickEvent=="openWin"){
                this.openWinEdit2(item,index)
            }
           
        },
        
        openWin(data){
            this.$emit("openWin",data);
            
        },
        
        goSearchList(){
            let el=this.$refs.inputSelectList;
            for(let i=0;i<el.length;i++){
                try{
                    el[i].goSearchList();
                }catch(e){}
                
            }
        },
         addRow(){
            let datas={};
            for(let i=0;i<this.listField.length;i++){
                datas[this.listField[i].id]='';
            }
            if(this.data[this.dataField+"_empty"]){
                datas={};
                datas=JSON.parse(JSON.stringify(this.data[this.dataField+"_empty"]))
               
            
            }
            //console.log("data=ssssssssssssssssssss==")
           // console.log(this.data[this.dataField+"_empty"]);
            //console.log(datas)
            this.$set(this.data[this.dataField],this.data[this.dataField].length,datas);
        },
        initSaveData(){//给编辑界面里有列表，列表里又有编辑界面的，而且编辑界面没有提交到后台保存，而是保存在了dataTemp json中，在保存前重新整理数据,这个主要是整理saveData方法中保存的数据
            let datas=[];
            
            console.log(this.dataTemp,"initSaveData==================")
            for(let key_ in this.dataTemp){
                for(let key in this.dataTemp[key_]){
                    if(this.dataTemp[key_][key].length!=undefined){
                        for(let i=0;i<this.dataTemp[key_][key].length;i++){
                            datas.push(this.dataTemp[key_][key][i])
                        }
                    }else{
                        datas.push(this.dataTemp[key_][key])
                    }
                }
                console.log("keys--------------"+key_);
                console.log(datas)
                this.$set(this.data,key_,datas);
                
            }
            
          
            
        },
        changeAmt(exdata){
            let exkey="";
            let extype="";
            let num=0;
            let amt=0;
            let total_amt=0;
            let total_amt_key="";
            let total_sub_key="";
           
            let num2=0

            for(let i=0;i<this.listField.length;i++){
                let _id=this.listField[i].id;
                let exkey_=this.listField[i].exkey;
                let extype_=this.listField[i].extype;
                if(exkey_){
                    exkey=exkey_;
                }
                if(extype_=="num"){
                    num=this.data[this.dataField][exdata][_id];
                }else if(extype_=="amt"){
                    amt=this.data[this.dataField][exdata][_id];
                }else if(extype_=="num2"){
                    num2=this.data[this.dataField][exdata][_id];
                }else if(extype_=="total_amt")
                    total_amt_key=_id;
                else if(extype_=="total_sub")
                    total_sub_key=_id;
            }
            if(total_amt_key){
                total_amt=num*amt;
                console.log("total_amt==="+total_amt)
                console.log(exkey,"exkeys================")
                //向下取整
                try{
                    if(exkey&&exkey.floor=="Y"){
                        total_amt=Math.floor(total_amt)
                    }
                }catch(e){}
                //向上取整
                 try{
                    if(exkey&&exkey.ceil=="Y"){
                        total_amt=Math.ceil(total_amt)
                    }
                }catch(e){}
                 //四舍五入
                 try{
                    if(exkey&&exkey.round=="Y"){
                        total_amt=Math.round(total_amt)
                    }
                }catch(e){}
                let data_=this.data[this.dataField][exdata];
                if(isNaN(total_amt)){
                    total_amt="";
                }
                if(data_[total_amt_key]!=""+total_amt){
                    data_[total_amt_key]=""+total_amt;
                    console.log("total_sub_key================="+total_amt)
                    this.$set(this.data[this.dataField],exdata,data_);
                }
                
                //this.setData(exdata,total_amt_key,total_amt);

            }
            if(total_sub_key){
                let num_sub=Number(num2)-Number(num);
                
                let data_=this.data[this.dataField][exdata];
               
                if(data_[total_sub_key]!=num_sub&&!isNaN(num_sub)){
                    console.log("total_sub_key2333333333333333================="+data_[total_sub_key]+"=="+num_sub)
                    data_[total_sub_key]=num_sub;
                    this.$set(this.data[this.dataField],exdata,data_);
                }
               
            }

            total_amt=0;
            for(let i=0;i<this.data[this.dataField].length;i++){
                total_amt+=Number(this.data[this.dataField][i][total_amt_key])
            }
            try{
                if(exkey){
                    let exkeys=exkey.split("#");
                    for(let h=0;h<exkeys.length;h++){
                        let data_={};
                        let ids=exkeys[h].split(".");
                        let p=ids[0];
                        let id_=ids[1];
                        data_.pre=p;
                        data_.val=total_amt;
                        data_.id=id_;
                        console.log("修改===============================")
                        this.$set(this.data[p],id_,total_amt);
                    }
                    
                    
                    //this.$emit("input",JSON.stringify(data_));

                }
            }catch(e){}
        },
        changeTotalAmt(){

            let total_amt_key="";
            let exkey="";
            for(let i=0;i<this.listField.length;i++){
                let _id=this.listField[i].id;
                let exkey_=this.listField[i].exkey;
                let extype_=this.listField[i].extype;
                if(exkey_){
                    exkey=exkey_;
                }
                if(extype_=="total_amt")
                    total_amt_key=_id;
            }
            let total_amt=0;
            for(let i=0;i<this.data[this.dataField].length;i++){
                total_amt+=Number(this.data[this.dataField][i][total_amt_key])
            }
            try{
                if(exkey){
                    let data_={};
                    let ids=exkey.split(".");
                    let p=ids[0];
                    let id_=ids[1];
                    data_.pre=p;
                    data_.val=total_amt;
                    data_.id=id_;
                    this.$set(this.data[p],id_,total_amt);
                    //this.$emit("input",JSON.stringify(data_));

                }
            }catch(e){}
            
        },
        tableChangeData(data){
            let datas=JSON.parse(data);
            let id=datas.id;
            let val=datas.val;
            let exdata=datas.exdata;
            let index=datas.index;
            if(exdata==undefined||exdata=="undefined"){
                datas.exdata=index;
                exdata=index;
            }

            let data_=this.data[this.dataField][exdata];
            data_[id]=val;
            //this.tableDataNew[exdata][id]=val;
            this.$set(this.data[this.dataField],exdata,data_);
            this.changeAmt(exdata);

           /* let data_={};
            data_.pre=this.dataField;
            data_.val=JSON.stringify(this.tableDataNew[exdata]);
            data_.exdata=exdata;
            this.$emit("input",JSON.stringify(data_));*/
        },
        addItem(data){
            
            /*let data_=JSON.parse(data);
            console.log("addItem========");
            console.log(data_);
            let data__={};
            data__.pre=this.dataField;
            data__.val=data;
            data__.exdata=this.tableDataNew.length;
            data__.type="add";
            console.log(data__);

            //已经存在的项目，则不在添加
            let isOk=true;
            for(let i=0;i<this.tableDataNew.length;i++){
                let keys=this.tableDataNew[i].keys;
                let keys_=data_.keys;
                if(keys==keys_&&keys)
                    isOk=false;
            }
            console.log("isOk===="+isOk)
            if(isOk){
                this.tableDataNew.push(data_);
                
                this.changeAmt(this.tableDataNew.length-1);
                this.$emit("input",JSON.stringify(data__));
            }
            console.log(this.tableDataNew)*/
                

        },
        removeItem(index){
          //  this.tableDataNew.splice(index,1);
            let data=this.data[this.dataField][index];
            this.$emit("removeItem",JSON.stringify(data))
            this.$delete(this.data[this.dataField],index);
            try{
                for(let key in this.dataTemp){
                    try{
                        if(this.dataTemp[key]["a"+index]){
                            delete this.dataTemp[key]["a"+index];
                        }
                    }catch(e){}
                }
                
            }catch(e){}
            try{
                let el=this.$refs.inputs;
                for(let i=0;i<el.length;i++){
                    el[i].setData();
                }
            }catch(e){}
            try{
                this.initSaveData();
            }catch(e){}
            this.changeTotalAmt();
           // this.$emit("remove",JSON.stringify(data));
            //console.log(this.tableDataNew)

        },
         removeItemByType(type){
            let index=-1;
            for(let i=0;i<this.data[this.dataField].length;i++){
                let szi_ex7=this.data[this.dataField][i].szi_ex7;
                if(szi_ex7==type){
                    index=i;
                }
            
            }
            
            if(index!=-1){
                this.$delete(this.data[this.dataField],index);
            }
            this.changeTotalAmt();
        },
        removeItemByName(name){
            let index=-1;
            for(let i=0;i<this.data[this.dataField].length;i++){
                let szi_ex1=this.data[this.dataField][i].szi_ex1;
                if(szi_ex1==name){
                    index=i;
                }
            
            }
            
            if(index!=-1){
                this.$delete(this.data[this.dataField],index);
            }
            this.changeTotalAmt();
        },
        getData(){
            return this.data[this.dataField];
        },
        setData(exdata,id,val){
            /*this.tableDataNew[exdata][id]=val;
            let els=this.$refs.inputs;
            if(els){
                for(let i=0;i<els.length;i++){
                    els[i].setData(exdata,id,val);
                }
            }*/
            
        },
        openWinEdit2(item,index){
            let exkey=JSON.parse(JSON.stringify(item.clickKey));
            this.openWinEditItem(exkey,exkey,index);
        },
        openWinEdit(item,index){
            let exkey=JSON.parse(JSON.stringify(item.exkey));
           // let obj=this.data[this.dataField][index];
           // console.log(obj,"obj===============")
            let condition=exkey.condition;
            let isOk=true;
            if(condition){
                
            }
            if(isOk)
                this.openWinEditItem(exkey,item,index);
            /*if(item.type=="inputLineButtonBeforeSave"){
                let exId=exkey.exId.split(".");
                let pId=exId[0];
                let id=exId[1];

                let idVal=this.data[pId][id];
                if(!idVal){
                    this.$message.error('请先保存');
                    return;
                }else{
                    exkey.exId=idVal;
                }
            }else{
                
                exkey.isSave="N";
            }
            this.dataType=item.extype;
            this.dataIndex=index;
            let sId=exkey.sId;
            if(sId){
                sId=this.data[this.dataField][index][sId];
            }
            exkey.sId=sId;
            
            this.data_exkey=exkey;
            let dataTemp="";
            if(this.dataTemp["a"+this.dataIndex]){
                dataTemp=JSON.stringify(this.dataTemp["a"+this.dataIndex]);
            }
            sessionStorage.setItem("commonEdit",dataTemp)
            this.$emit("openWinEdit",JSON.stringify(exkey))*/
        },
        openWinEditItem(exkey,item,index){
             if(item.type=="inputLineButtonBeforeSave"){
                let exId=exkey.exId.split(".");
                let pId=exId[0];
                let id=exId[1];
                let idVal=this.data[pId][id];

                if(!idVal){
                    this.$message.error('请先保存');
                    return;
                }else{
                    exkey.exId=idVal;
                }
            }else{
                if(!exkey.isSave)
                    exkey.isSave="N";
            }
          
            this.dataType=item.extype;
            this.dataIndex=index;
            let sId=exkey.sId;
           // alert(this.dataField+"=="+index)
            if(sId){
                sId=this.data[this.dataField][index][sId];
            }
            exkey.sId=sId;
            
            this.data_exkey=exkey;
            let dataTemp="";
            try{
                if(this.dataTemp[this.dataType]["a"+this.dataIndex]){
                    dataTemp=JSON.stringify(this.dataTemp[this.dataType]["a"+this.dataIndex]);
                }
            }catch(e){}

           
            sessionStorage.setItem("commonEdit",dataTemp)
            sessionStorage.setItem("commonEditField",this.dataType)

            if(!exkey.width){
                exkey.width="90%";
            }
            if(!exkey.height){
                exkey.height="height:85VH";
            }
           
            this.$emit("openWinEdit",JSON.stringify(exkey))
        },
        saveData(data){//tabMain.vue页面调用，这个只要是这个列表界面又开了一个编辑界面，编辑界面没有保存后台，点击保存后把数据传给列表，列表把数据展示出来，目前只处理字段相同的给展示出来，编辑界面已经把数据封装到this.data中
          
           sessionStorage.setItem("commonEdit","")
            let item=data.data[this.dataType]; //this.dataType相当于dataField和pre
            console.log(item,"saveData====item======")
            let key_field=this.data_exkey.key_field; //key_field外键，this.data_exkey是打开这个编辑界面按钮的exkey
            for(let i=0;i<item.length;i++){
                item[i][key_field]=this.data_exkey["sId"];//保存关联外键,this.data_exkey里的sId本来存的是外键字段，但在打开编辑界面的时候，把他替换成了真实的数据，比如这里是把墓位ID，存入安葬表中
            }
          
            if(!this.dataTemp[this.dataType]){
                this.dataTemp[this.dataType]={}
            }
            
            console.log(item,"saveData====item=====2222=")
            this.dataTemp[this.dataType]["a"+this.dataIndex]=item;//把数据放入临时json集合中，在总编辑界面点保存的时候，在统一整理
         
            this.initSaveData();
            let item_=this.data[this.dataField+"_empty"];
           
          //  alert(2);
            for(let key in item_){
                let isOk=false;
                let val="";
                if(item.length!=undefined){//集合
                    for(let i=0;i<item.length;i++){
                        for(let key_ in item[i]){
                            if(key==key_){
                                isOk=true;
                                val=val=="" ? item[i][key_]:val+","+item[i][key_];//主要针对打开的编辑界面是一个列表界面，所以要拼接字符串
                            
                            }
                        }
                    }
                    if(isOk){
                        this.$set(this.data[this.dataField][this.dataIndex],key,val)//在总的编辑界面的列表界面中显示相关字段，目前只显示列表中的字段跟打开的编辑界面的字段是相同的
                    
                        
                    }
                }else{
                    for(let key_ in item){
                        if(key==key_){
                            isOk=true;
                            val=item[key];
                        }
                    }
                    if(isOk)
                    this.$set(this.data[this.dataField][this.dataIndex],key,val)//在总的编辑界面的列表界面中显示相关字段，目前只显示列表中的字段跟打开的编辑界面的字段是相同的
                    
                }
                
               
            }
        },
        opened2(){
            let sef=this;
           // window.setTimeout(function(){
                let maxWidth=document.body.clientWidth;
                let maxHeight=document.body.clientHeight;

                let width=sef.commonEditData2.width;
                let height=sef.commonEditData2.height;
                if(width.indexOf("px")!=-1){
                    let left=(maxWidth-Number(width.replace("px","")))/2
                    let top=(maxHeight-Number(height.replace("px","").replace("height:","")))/2
                    let els=document.getElementsByClassName("dialog-vertical2")[document.getElementsByClassName("dialog-vertical2").length-1];
                    let els2=els.getElementsByClassName("el-dialog")[0];
                    els2.style.left=left+"px";
                    els2.style.top=top+"px";
                }else{
                    let els=document.getElementsByClassName("dialog-vertical2")[document.getElementsByClassName("dialog-vertical2").length-1];
                    let els2=els.getElementsByClassName("el-dialog")[0];
                    els2.style.left=sef.commonEditData.left.replace("VH","%").replace("vh","%");
                    els2.style.top=sef.commonEditData.top.replace("VH","%").replace("vh","%");
                }
               
           // },1000)
        },
    }
}
</script>
<style scoped>
    .tabActive{
        background:#409EFF !important;
        color:#fff !important;
    }
    table{
        width:100%;
        border-collapse: collapse;
    }
    th{
        border:1px solid #409EFF;
        padding:5px;
        background:#409EFF;
        color:#fff;
        
    }
    td{
        border:1px solid #ddd;
    }
    input{
        border:0;
    }
    .tablesss{
        flex:1;
    }
    .el-table{
        flex:1;
    }
    .tableEdit{
        
        overflow:hidden;
        display:flex;
        flex-direction: column;
        height:100%;
        text-align:left;
    }
    .activeRow{
        background:#d3e8fe;
    }
    
    .activeRow input{
        background:#d3e8fe;
    }
</style>